testsuite: Add tests for the new node parsing code
authorBenjamin Otte <otte@redhat.com>
Tue, 19 Mar 2019 04:29:20 +0000 (05:29 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 5 May 2019 05:18:39 +0000 (07:18 +0200)
This adds a test tool gsk/node-parser that takes node files and parses
them.

A few of these node files have been added, for crashes I encountered while
developing the new parsing code.

testsuite/gsk/meson.build
testsuite/gsk/node-parser.c [new file with mode: 0644]
testsuite/gsk/nodeparser/crash1.node [new file with mode: 0644]
testsuite/gsk/nodeparser/crash2.node [new file with mode: 0644]
testsuite/gsk/nodeparser/crash3.node [new file with mode: 0644]

index f2568a6710e9df79c5d464c2b5885aacb11324c1..fcfc1d05f88780213926cbca16e9faee16997eea 100644 (file)
@@ -18,6 +18,14 @@ compare_render = executable(
   install_dir: testexecdir
 )
 
+node_parser = executable(
+  'node-parser',
+  ['node-parser.c'],
+  dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir
+)
+
 test('nodes (cairo)', test_render_nodes,
      args: [ '--tap', '-k' ],
      env: [ 'GIO_USE_VOLUME_MONITOR=unix',
@@ -70,6 +78,26 @@ foreach gl_test : gl_tests
        suite: 'gsk')
 endforeach
 
+node_parser_tests = [
+  'crash1',
+  'crash2',
+  'crash3',
+]
+
+foreach test : node_parser_tests
+  test('parser ' + test, node_parser,
+       args: [join_paths(meson.current_source_dir(), 'nodeparser', test + '.node')],
+       env: [ 'GIO_USE_VOLUME_MONITOR=unix',
+              'GSETTINGS_BACKEND=memory',
+              'GTK_CSD=1',
+              'G_ENABLE_DIAGNOSTIC=0',
+              'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+              'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+              'GSK_RENDERER=opengl'
+            ],
+       suite: 'gsk')
+endforeach
+
 if have_vulkan
   test('nodes (vulkan)', test_render_nodes,
        args: [ '--tap', '-k' ],
diff --git a/testsuite/gsk/node-parser.c b/testsuite/gsk/node-parser.c
new file mode 100644 (file)
index 0000000..397b13f
--- /dev/null
@@ -0,0 +1,30 @@
+#include <gtk/gtk.h>
+
+int
+main (int argc, char **argv)
+{
+  GError *error = NULL;
+  GskRenderNode *node;
+  GBytes *bytes;
+  GFile *file;
+
+  g_assert (argc == 2);
+
+  gtk_init ();
+
+  file = g_file_new_for_commandline_arg (argv[1]);
+  bytes = g_file_load_bytes (file, NULL, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (bytes != NULL);
+
+  node = gsk_render_node_deserialize (bytes, &error);
+  if (error)
+    g_test_message ("Error: %s\n", error->message);
+
+  g_clear_error (&error);
+  g_clear_pointer (&node, gsk_render_node_unref);
+  g_bytes_unref (bytes);
+  g_object_unref (file);
+
+  return 0;
+}
diff --git a/testsuite/gsk/nodeparser/crash1.node b/testsuite/gsk/nodeparser/crash1.node
new file mode 100644 (file)
index 0000000..bba912e
--- /dev/null
@@ -0,0 +1,2 @@
+opacity {
+  child = color {
diff --git a/testsuite/gsk/nodeparser/crash2.node b/testsuite/gsk/nodeparser/crash2.node
new file mode 100644 (file)
index 0000000..677e9f2
--- /dev/null
@@ -0,0 +1,3 @@
+cross-fade {
+  from: color {
+    co
diff --git a/testsuite/gsk/nodeparser/crash3.node b/testsuite/gsk/nodeparser/crash3.node
new file mode 100644 (file)
index 0000000..3d89f88
--- /dev/null
@@ -0,0 +1,18 @@
+cross-fade {
+  start: container {
+    color {
+      color: red;
+      bounds: 0 0 10 10;
+    }
+    color {
+      color: green;
+      bounds: 10 10 10 10;
+    }
+  }
+  end: color {
+    color: blue;
+    bounds: 5 5 10 10;
+  }
+  progress: 0.2;
+}
+